.class public Lcom/android/inputmethod/latin/MetaKeyHandler;
.super Ljava/lang/Object;
.source "MetaKeyHandler.java"


# static fields
.field static final TAG:Ljava/lang/String; = "MetaKeyHandler"


# instance fields
.field mIc:Landroid/view/inputmethod/InputConnection;

.field mMetaKeyState:J


# direct methods
.method public constructor <init>()V
    .locals 3

    .prologue
    const-wide/16 v1, 0x0

    const/4 v0, 0x0

    .line 24
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 21
    iput-wide v1, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    .line 22
    iput-object v0, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mIc:Landroid/view/inputmethod/InputConnection;

    .line 25
    iput-wide v1, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    .line 26
    iput-object v0, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mIc:Landroid/view/inputmethod/InputConnection;

    .line 27
    return-void
.end method


# virtual methods
.method public adjustMetaStateAfterKeyPress(ILandroid/view/KeyEvent;Z)Z
    .locals 2
    .parameter "keyCode"
    .parameter "event"
    .parameter "handled"

    .prologue
    .line 72
    invoke-virtual {p0, p1, p2}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isMetaKey(ILandroid/view/KeyEvent;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 73
    const/4 v0, 0x0

    .line 82
    :goto_0
    return v0

    .line 76
    :cond_0
    iget-wide v0, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    invoke-static {v0, v1}, Landroid/text/method/MetaKeyKeyListener;->adjustMetaAfterKeypress(J)J

    move-result-wide v0

    iput-wide v0, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    .line 78
    if-eqz p3, :cond_1

    .line 79
    invoke-virtual {p0}, Lcom/android/inputmethod/latin/MetaKeyHandler;->syncMetaState()V

    .line 82
    :cond_1
    const/4 v0, 0x1

    goto :goto_0
.end method

.method public clearMetaState()V
    .locals 2

    .prologue
    .line 135
    const-wide/16 v0, 0x0

    iput-wide v0, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    .line 136
    return-void
.end method

.method createNewKeyEvent(IILandroid/view/KeyEvent;)Landroid/view/KeyEvent;
    .locals 12
    .parameter "newMetaState"
    .parameter "keyCode"
    .parameter "event"

    .prologue
    .line 264
    new-instance v0, Landroid/view/KeyEvent;

    invoke-virtual {p3}, Landroid/view/KeyEvent;->getDownTime()J

    move-result-wide v1

    invoke-virtual {p3}, Landroid/view/KeyEvent;->getEventTime()J

    move-result-wide v3

    invoke-virtual {p3}, Landroid/view/KeyEvent;->getAction()I

    move-result v5

    invoke-virtual {p3}, Landroid/view/KeyEvent;->getKeyCode()I

    move-result v6

    invoke-virtual {p3}, Landroid/view/KeyEvent;->getRepeatCount()I

    move-result v7

    invoke-virtual {p3}, Landroid/view/KeyEvent;->getDeviceId()I

    move-result v9

    invoke-virtual {p3}, Landroid/view/KeyEvent;->getScanCode()I

    move-result v10

    invoke-virtual {p3}, Landroid/view/KeyEvent;->getFlags()I

    move-result v11

    move v8, p1

    invoke-direct/range {v0 .. v11}, Landroid/view/KeyEvent;-><init>(JJIIIIIII)V

    return-object v0
.end method

.method public getMetaState(I)I
    .locals 2
    .parameter "meta"

    .prologue
    .line 208
    iget-wide v0, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    invoke-static {v0, v1, p1}, Landroid/text/method/MetaKeyKeyListener;->getMetaState(JI)I

    move-result v0

    return v0
.end method

.method public handleKeyDown(ILandroid/view/KeyEvent;)Landroid/view/KeyEvent;
    .locals 3
    .parameter "keyCode"
    .parameter "event"

    .prologue
    .line 51
    const/4 v0, 0x0

    .line 52
    .local v0, evt:Landroid/view/KeyEvent;
    invoke-virtual {p0, p1, p2}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isMetaKey(ILandroid/view/KeyEvent;)Z

    move-result v1

    if-eqz v1, :cond_0

    .line 54
    iget-wide v1, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    invoke-static {v1, v2, p1, p2}, Landroid/text/method/MetaKeyKeyListener;->handleKeyDown(JILandroid/view/KeyEvent;)J

    move-result-wide v1

    iput-wide v1, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    .line 64
    :goto_0
    return-object v0

    .line 57
    :cond_0
    iget-wide v1, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    invoke-virtual {p0, v1, v2}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isMetaFlagNecessary(J)Z

    move-result v1

    if-eqz v1, :cond_1

    .line 59
    iget-wide v1, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    invoke-virtual {p0, v1, v2, p1, p2}, Lcom/android/inputmethod/latin/MetaKeyHandler;->updateKeyEvent(JILandroid/view/KeyEvent;)Landroid/view/KeyEvent;

    move-result-object v0

    goto :goto_0

    .line 61
    :cond_1
    move-object v0, p2

    goto :goto_0
.end method

.method public handleKeyUp(ILandroid/view/KeyEvent;)Landroid/view/KeyEvent;
    .locals 3
    .parameter "keyCode"
    .parameter "event"

    .prologue
    .line 118
    const/4 v0, 0x0

    .line 119
    .local v0, evt:Landroid/view/KeyEvent;
    invoke-virtual {p0, p1, p2}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isMetaKey(ILandroid/view/KeyEvent;)Z

    move-result v1

    if-eqz v1, :cond_0

    .line 121
    iget-wide v1, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    invoke-static {v1, v2, p1, p2}, Landroid/text/method/MetaKeyKeyListener;->handleKeyUp(JILandroid/view/KeyEvent;)J

    move-result-wide v1

    iput-wide v1, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    .line 123
    invoke-virtual {p0}, Lcom/android/inputmethod/latin/MetaKeyHandler;->syncMetaState()V

    .line 128
    :goto_0
    return-object v0

    .line 125
    :cond_0
    move-object v0, p2

    goto :goto_0
.end method

.method isAlt(ILandroid/view/KeyEvent;)Z
    .locals 1
    .parameter "keyCode"
    .parameter "event"

    .prologue
    .line 163
    const/16 v0, 0x39

    if-eq p1, v0, :cond_0

    const/16 v0, 0x3a

    if-eq p1, v0, :cond_0

    const/16 v0, 0x5d

    if-eq p1, v0, :cond_0

    const/16 v0, 0x4e

    if-ne p1, v0, :cond_1

    .line 168
    :cond_0
    const/4 v0, 0x1

    .line 171
    :goto_0
    return v0

    :cond_1
    const/4 v0, 0x0

    goto :goto_0
.end method

.method isAltNeededForKeyEvent(ILandroid/view/KeyEvent;)Z
    .locals 2
    .parameter "keyCode"
    .parameter "event"

    .prologue
    .line 250
    const/4 v0, 0x1

    .line 252
    .local v0, ret:Z
    const/16 v1, 0x43

    if-eq p1, v1, :cond_0

    const/16 v1, 0x42

    if-ne p1, v1, :cond_1

    .line 255
    :cond_0
    const/4 v0, 0x0

    .line 258
    :cond_1
    return v0
.end method

.method isMetaFlagNecessary(J)Z
    .locals 3
    .parameter "state"

    .prologue
    const/4 v2, 0x1

    .line 186
    const/4 v1, 0x2

    invoke-virtual {p0, p1, p2, v1}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isMetaKeyPressedFlagNecessary(JI)Z

    move-result v1

    if-nez v1, :cond_0

    invoke-virtual {p0, p1, p2, v2}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isMetaKeyPressedFlagNecessary(JI)Z

    move-result v1

    if-nez v1, :cond_0

    const/4 v1, 0x4

    invoke-virtual {p0, p1, p2, v1}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isMetaKeyPressedFlagNecessary(JI)Z

    move-result v1

    if-eqz v1, :cond_1

    :cond_0
    move v0, v2

    .line 190
    .local v0, ret:Z
    :goto_0
    return v0

    .line 186
    .end local v0           #ret:Z
    :cond_1
    const/4 v1, 0x0

    move v0, v1

    goto :goto_0
.end method

.method isMetaKey(ILandroid/view/KeyEvent;)Z
    .locals 1
    .parameter "keyCode"
    .parameter "event"

    .prologue
    .line 143
    invoke-virtual {p0, p1, p2}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isShift(ILandroid/view/KeyEvent;)Z

    move-result v0

    if-nez v0, :cond_0

    invoke-virtual {p0, p1, p2}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isAlt(ILandroid/view/KeyEvent;)Z

    move-result v0

    if-nez v0, :cond_0

    invoke-virtual {p0, p1, p2}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isSym(ILandroid/view/KeyEvent;)Z

    move-result v0

    if-eqz v0, :cond_1

    .line 144
    :cond_0
    const/4 v0, 0x1

    .line 147
    :goto_0
    return v0

    :cond_1
    const/4 v0, 0x0

    goto :goto_0
.end method

.method isMetaKeyPressedFlagNecessary(JI)Z
    .locals 4
    .parameter "state"
    .parameter "metaKeyOnMask"

    .prologue
    const/4 v3, 0x1

    const/4 v2, 0x0

    .line 194
    const/4 v1, 0x2

    if-eq p3, v1, :cond_0

    if-eq p3, v3, :cond_0

    const/4 v1, 0x4

    if-eq p3, v1, :cond_0

    move v1, v2

    .line 202
    :goto_0
    return v1

    .line 200
    :cond_0
    invoke-static {p1, p2, p3}, Landroid/text/method/MetaKeyKeyListener;->getMetaState(JI)I

    move-result v0

    .line 202
    .local v0, metaState:I
    if-eqz v0, :cond_1

    move v1, v3

    goto :goto_0

    :cond_1
    move v1, v2

    goto :goto_0
.end method

.method isShift(ILandroid/view/KeyEvent;)Z
    .locals 1
    .parameter "keyCode"
    .parameter "event"

    .prologue
    .line 153
    const/16 v0, 0x3b

    if-eq p1, v0, :cond_0

    const/16 v0, 0x3c

    if-ne p1, v0, :cond_1

    .line 154
    :cond_0
    const/4 v0, 0x1

    .line 157
    :goto_0
    return v0

    :cond_1
    const/4 v0, 0x0

    goto :goto_0
.end method

.method isSym(ILandroid/view/KeyEvent;)Z
    .locals 1
    .parameter "keyCode"
    .parameter "event"

    .prologue
    .line 177
    const/16 v0, 0x3f

    if-ne p1, v0, :cond_0

    .line 178
    const/4 v0, 0x1

    .line 181
    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

.method public startInput(Landroid/inputmethodservice/InputMethodService;Landroid/view/inputmethod/EditorInfo;Z)V
    .locals 2
    .parameter "ims"
    .parameter "ei"
    .parameter "restarting"

    .prologue
    .line 35
    const-wide/16 v0, 0x0

    iput-wide v0, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    .line 38
    invoke-virtual {p1}, Landroid/inputmethodservice/InputMethodService;->getCurrentInputConnection()Landroid/view/inputmethod/InputConnection;

    move-result-object v0

    iput-object v0, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mIc:Landroid/view/inputmethod/InputConnection;

    .line 39
    iget-object v0, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mIc:Landroid/view/inputmethod/InputConnection;

    if-eqz v0, :cond_0

    .line 40
    iget-object v0, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mIc:Landroid/view/inputmethod/InputConnection;

    const/4 v1, 0x7

    invoke-interface {v0, v1}, Landroid/view/inputmethod/InputConnection;->clearMetaKeyStates(I)Z

    .line 42
    :cond_0
    return-void
.end method

.method syncMetaState()V
    .locals 5

    .prologue
    .line 90
    const/4 v0, 0x0

    .line 91
    .local v0, clearState:I
    const/4 v1, 0x0

    .line 92
    .local v1, meta:I
    iget-wide v2, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    const/4 v4, 0x2

    invoke-static {v2, v3, v4}, Landroid/text/method/MetaKeyKeyListener;->getMetaState(JI)I

    move-result v1

    .line 93
    if-nez v1, :cond_0

    .line 94
    or-int/lit8 v0, v0, 0x2

    .line 97
    :cond_0
    iget-wide v2, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    const/4 v4, 0x1

    invoke-static {v2, v3, v4}, Landroid/text/method/MetaKeyKeyListener;->getMetaState(JI)I

    move-result v1

    .line 98
    if-nez v1, :cond_1

    .line 99
    or-int/lit8 v0, v0, 0x1

    .line 102
    :cond_1
    iget-wide v2, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mMetaKeyState:J

    const/4 v4, 0x4

    invoke-static {v2, v3, v4}, Landroid/text/method/MetaKeyKeyListener;->getMetaState(JI)I

    move-result v1

    .line 103
    if-nez v1, :cond_2

    .line 104
    or-int/lit8 v0, v0, 0x4

    .line 107
    :cond_2
    if-eqz v0, :cond_3

    iget-object v2, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mIc:Landroid/view/inputmethod/InputConnection;

    if-eqz v2, :cond_3

    .line 108
    iget-object v2, p0, Lcom/android/inputmethod/latin/MetaKeyHandler;->mIc:Landroid/view/inputmethod/InputConnection;

    invoke-interface {v2, v0}, Landroid/view/inputmethod/InputConnection;->clearMetaKeyStates(I)Z

    .line 110
    :cond_3
    return-void
.end method

.method updateKeyEvent(JILandroid/view/KeyEvent;)Landroid/view/KeyEvent;
    .locals 7
    .parameter "state"
    .parameter "keyCode"
    .parameter "event"

    .prologue
    .line 214
    const/4 v1, 0x0

    .line 215
    .local v1, evt:Landroid/view/KeyEvent;
    invoke-virtual {p4}, Landroid/view/KeyEvent;->getMetaState()I

    move-result v4

    .line 216
    .local v4, oldMetaState:I
    move v3, v4

    .line 218
    .local v3, newMetaState:I
    invoke-static {p1, p2}, Landroid/text/method/MetaKeyKeyListener;->getMetaState(J)I

    move-result v2

    .line 219
    .local v2, metaState:I
    const/4 v0, 0x0

    .line 222
    .local v0, delta:I
    const/4 v5, 0x2

    invoke-virtual {p0, p1, p2, v5}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isMetaKeyPressedFlagNecessary(JI)Z

    move-result v5

    if-eqz v5, :cond_0

    invoke-virtual {p0, p3, p4}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isAltNeededForKeyEvent(ILandroid/view/KeyEvent;)Z

    move-result v5

    if-eqz v5, :cond_0

    .line 223
    const/4 v0, 0x2

    .line 224
    or-int/2addr v3, v0

    .line 228
    :cond_0
    const/4 v5, 0x1

    invoke-virtual {p0, p1, p2, v5}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isMetaKeyPressedFlagNecessary(JI)Z

    move-result v5

    if-eqz v5, :cond_1

    .line 229
    const/4 v0, 0x1

    .line 230
    or-int/2addr v3, v0

    .line 234
    :cond_1
    const/4 v5, 0x4

    invoke-virtual {p0, p1, p2, v5}, Lcom/android/inputmethod/latin/MetaKeyHandler;->isMetaKeyPressedFlagNecessary(JI)Z

    move-result v5

    if-eqz v5, :cond_2

    .line 235
    const/4 v0, 0x4

    .line 236
    or-int/2addr v3, v0

    .line 239
    :cond_2
    if-ne v3, v4, :cond_3

    .line 240
    move-object v1, p4

    .line 246
    :goto_0
    return-object v1

    .line 242
    :cond_3
    const-string v5, "MetaKeyHandler"

    const-string v6, "create a new event with new meta state"

    invoke-static {v5, v6}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 243
    invoke-virtual {p0, v3, p3, p4}, Lcom/android/inputmethod/latin/MetaKeyHandler;->createNewKeyEvent(IILandroid/view/KeyEvent;)Landroid/view/KeyEvent;

    move-result-object v1

    goto :goto_0
.end method
